

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.dataset.CelebADataset &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.dataset.Cifar10Dataset" href="mindspore.dataset.Cifar10Dataset.html" />
    <link rel="prev" title="mindspore.dataset.Caltech256Dataset" href="mindspore.dataset.Caltech256Dataset.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.dataset.html#id1">视觉</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.Caltech101Dataset.html">mindspore.dataset.Caltech101Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.Caltech256Dataset.html">mindspore.dataset.Caltech256Dataset</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.dataset.CelebADataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.Cifar10Dataset.html">mindspore.dataset.Cifar10Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.Cifar100Dataset.html">mindspore.dataset.Cifar100Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.CityscapesDataset.html">mindspore.dataset.CityscapesDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.CocoDataset.html">mindspore.dataset.CocoDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.DIV2KDataset.html">mindspore.dataset.DIV2KDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.EMnistDataset.html">mindspore.dataset.EMnistDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.FakeImageDataset.html">mindspore.dataset.FakeImageDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.FashionMnistDataset.html">mindspore.dataset.FashionMnistDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.FlickrDataset.html">mindspore.dataset.FlickrDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.Flowers102Dataset.html">mindspore.dataset.Flowers102Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.ImageFolderDataset.html">mindspore.dataset.ImageFolderDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.KMnistDataset.html">mindspore.dataset.KMnistDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.ManifestDataset.html">mindspore.dataset.ManifestDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.MnistDataset.html">mindspore.dataset.MnistDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.PhotoTourDataset.html">mindspore.dataset.PhotoTourDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.Places365Dataset.html">mindspore.dataset.Places365Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.QMnistDataset.html">mindspore.dataset.QMnistDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.SBDataset.html">mindspore.dataset.SBDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.SBUDataset.html">mindspore.dataset.SBUDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.SemeionDataset.html">mindspore.dataset.SemeionDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.STL10Dataset.html">mindspore.dataset.STL10Dataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.SVHNDataset.html">mindspore.dataset.SVHNDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.USPSDataset.html">mindspore.dataset.USPSDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.VOCDataset.html">mindspore.dataset.VOCDataset</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.WIDERFaceDataset.html">mindspore.dataset.WIDERFaceDataset</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id2">文本</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id3">音频</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id4">标准格式</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id5">用户自定义</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id6">图</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id7">采样器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id8">其他</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.dataset.html">mindspore.dataset</a> &raquo;</li>
        
      <li>mindspore.dataset.CelebADataset</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/dataset/mindspore.dataset.CelebADataset.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-dataset-celebadataset">
<h1>mindspore.dataset.CelebADataset<a class="headerlink" href="#mindspore-dataset-celebadataset" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.dataset.CelebADataset">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.dataset.</code><code class="sig-name descname">CelebADataset</code><span class="sig-paren">(</span><em class="sig-param">dataset_dir</em>, <em class="sig-param">num_parallel_workers=None</em>, <em class="sig-param">shuffle=None</em>, <em class="sig-param">usage='all'</em>, <em class="sig-param">sampler=None</em>, <em class="sig-param">decode=False</em>, <em class="sig-param">extensions=None</em>, <em class="sig-param">num_samples=None</em>, <em class="sig-param">num_shards=None</em>, <em class="sig-param">shard_id=None</em>, <em class="sig-param">cache=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset" title="Permalink to this definition">¶</a></dt>
<dd><p>读取和解析CelebA数据集的源文件构建数据集。目前仅支持解析CelebA数据集中的 <cite>list_attr_celeba.txt</cite> 文件作为数据集的label。</p>
<p>生成的数据集有两列 <cite>[image, attr]</cite> 。 <cite>image</cite> 列的数据类型为uint8。<cite>attr</cite> 列的数据类型为uint32，并以one-hot编码的形式生成。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>dataset_dir</strong> (str) - 包含数据集文件的根目录路径。</p></li>
<li><p><strong>num_parallel_workers</strong> (int, 可选) - 指定读取数据的工作线程数。默认值：None，使用mindspore.dataset.config中配置的线程数。</p></li>
<li><p><strong>shuffle</strong> (bool, 可选) - 是否混洗数据集。默认值：None，下表中会展示不同参数配置的预期行为。</p></li>
<li><p><strong>usage</strong> (str, 可选) - 指定数据集的子集，可取值为’train’，’valid’，’test’或’all’。默认值：’all’，全部样本图片。</p></li>
<li><p><strong>sampler</strong> (Sampler, 可选) - 指定从数据集中选取样本的采样器，默认值：None，下表中会展示不同配置的预期行为。</p></li>
<li><p><strong>decode</strong> (bool, 可选) - 是否对读取的图片进行解码操作，默认值：False，不解码。</p></li>
<li><p><strong>extensions</strong> (list[str], 可选) - 指定文件的扩展名，仅读取与指定扩展名匹配的文件到数据集中，默认值：None。</p></li>
<li><p><strong>num_samples</strong> (int, 可选) - 指定从数据集中读取的样本数，可以小于数据集总数。默认值：None，读取全部样本图片。</p></li>
<li><p><strong>num_shards</strong> (int, 可选) - 指定分布式训练时将数据集进行划分的分片数，默认值：None。指定此参数后， <cite>num_samples</cite> 表示每个分片的最大样本数。</p></li>
<li><p><strong>shard_id</strong> (int, 可选) - 指定分布式训练时使用的分片ID号，默认值：None。只有当指定了 <cite>num_shards</cite> 时才能指定此参数。</p></li>
<li><p><strong>cache</strong> (DatasetCache, 可选) - 单节点数据缓存服务，用于加快数据集处理，详情请阅读 <a class="reference external" href="https://www.mindspore.cn/docs/programming_guide/zh-CN/master/cache.html">单节点数据缓存</a> 。默认值：None，不使用缓存。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>RuntimeError</strong> - <cite>dataset_dir</cite> 路径下不包含任何数据文件。</p></li>
<li><p><strong>ValueError</strong> - <cite>num_parallel_workers</cite> 参数超过系统最大线程数。</p></li>
<li><p><strong>ValueError</strong> - <cite>usage</cite> 参数取值不为’train’、’valid’、’test’或’all’。</p></li>
<li><p><strong>RuntimeError</strong> - 同时指定了 <cite>sampler</cite> 和 <cite>shuffle</cite> 参数。</p></li>
<li><p><strong>RuntimeError</strong> - 同时指定了 <cite>sampler</cite> 和 <cite>num_shards</cite> 参数或同时指定了 <cite>sampler</cite> 和 <cite>shard_id</cite> 参数。</p></li>
<li><p><strong>RuntimeError</strong> - 指定了 <cite>num_shards</cite> 参数，但是未指定 <cite>shard_id</cite> 参数。</p></li>
<li><p><strong>RuntimeError</strong> - 指定了 <cite>shard_id</cite> 参数，但是未指定 <cite>num_shards</cite> 参数。</p></li>
<li><p><strong>ValueError</strong> - <cite>shard_id</cite> 参数值错误（小于0或者大于等于 <cite>num_shards</cite> ）。</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>此数据集可以指定参数 <cite>sampler</cite> ，但参数 <cite>sampler</cite> 和参数 <cite>shuffle</cite> 的行为是互斥的。下表展示了几种合法的输入参数组合及预期的行为。</p>
</div>
<table class="colwidths-given docutils align-default" id="id4">
<caption><span class="caption-text">配置 <cite>sampler</cite> 和 <cite>shuffle</cite> 的不同组合得到的预期排序结果</span><a class="headerlink" href="#id4" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>参数 <cite>sampler</cite></p></th>
<th class="head"><p>参数 <cite>shuffle</cite></p></th>
<th class="head"><p>预期数据顺序</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>None</p></td>
<td><p>None</p></td>
<td><p>随机排列</p></td>
</tr>
<tr class="row-odd"><td><p>None</p></td>
<td><p>True</p></td>
<td><p>随机排列</p></td>
</tr>
<tr class="row-even"><td><p>None</p></td>
<td><p>False</p></td>
<td><p>顺序排列</p></td>
</tr>
<tr class="row-odd"><td><p><cite>sampler</cite> 实例</p></td>
<td><p>None</p></td>
<td><p>由 <cite>sampler</cite> 行为定义的顺序</p></td>
</tr>
<tr class="row-even"><td><p><cite>sampler</cite> 实例</p></td>
<td><p>True</p></td>
<td><p>不允许</p></td>
</tr>
<tr class="row-odd"><td><p><cite>sampler</cite> 实例</p></td>
<td><p>False</p></td>
<td><p>不允许</p></td>
</tr>
</tbody>
</table>
<p><strong>关于CelebA数据集：</strong></p>
<p>CelebFaces Attributes Dataset（CelebA）数据集是一个大规模的人脸属性数据集，拥有超过20万张名人图像，每个图像都有40个属性标注。此数据集包含了大量不同姿态、各种背景的人脸图像，种类丰富、数量庞大、标注充分。数据集总体包含：</p>
<ul class="simple">
<li><p>10177个不同的身份</p></li>
<li><p>202599张人脸图像</p></li>
<li><p>每张图像拥有5个五官位置标注，40个属性标签</p></li>
</ul>
<p>此数据集可用于各种计算机视觉任务的训练和测试，包括人脸识别、人脸检测、五官定位、人脸编辑和合成等。</p>
<p>原始CelebA数据集结构：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>.
└── CelebA
     ├── README.md
     ├── Img
     │    ├── img_celeba.7z
     │    ├── img_align_celeba_png.7z
     │    └── img_align_celeba.zip
     ├── Eval
     │    └── list_eval_partition.txt
     └── Anno
          ├── list_landmarks_celeba.txt
          ├── list_landmarks_align_celeba.txt
          ├── list_bbox_celeba.txt
          ├── list_attr_celeba.txt
          └── identity_CelebA.txt
</pre></div>
</div>
<p>您可以将上述Anno目录下的txt文件与Img目录下的文件解压放至同一目录，并通过MindSpore的API进行读取。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>.
└── celeba_dataset_directory
    ├── list_attr_celeba.txt
    ├── 000001.jpg
    ├── 000002.jpg
    ├── 000003.jpg
    ├── ...
</pre></div>
</div>
<p><strong>引用：</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@article</span><span class="p">{</span><span class="n">DBLP</span><span class="p">:</span><span class="n">journals</span><span class="o">/</span><span class="n">corr</span><span class="o">/</span><span class="n">LiuLWT14</span><span class="p">,</span>
<span class="n">author</span>        <span class="o">=</span> <span class="p">{</span><span class="n">Ziwei</span> <span class="n">Liu</span> <span class="ow">and</span> <span class="n">Ping</span> <span class="n">Luo</span> <span class="ow">and</span> <span class="n">Xiaogang</span> <span class="n">Wang</span> <span class="ow">and</span> <span class="n">Xiaoou</span> <span class="n">Tang</span><span class="p">},</span>
<span class="n">title</span>         <span class="o">=</span> <span class="p">{</span><span class="n">Deep</span> <span class="n">Learning</span> <span class="n">Face</span> <span class="n">Attributes</span> <span class="ow">in</span> <span class="n">the</span> <span class="n">Wild</span><span class="p">},</span>
<span class="n">journal</span>       <span class="o">=</span> <span class="p">{</span><span class="n">CoRR</span><span class="p">},</span>
<span class="n">volume</span>        <span class="o">=</span> <span class="p">{</span><span class="nb">abs</span><span class="o">/</span><span class="mf">1411.7766</span><span class="p">},</span>
<span class="n">year</span>          <span class="o">=</span> <span class="p">{</span><span class="mi">2014</span><span class="p">},</span>
<span class="n">url</span>           <span class="o">=</span> <span class="p">{</span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">arxiv</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="nb">abs</span><span class="o">/</span><span class="mf">1411.7766</span><span class="p">},</span>
<span class="n">archivePrefix</span> <span class="o">=</span> <span class="p">{</span><span class="n">arXiv</span><span class="p">},</span>
<span class="n">eprint</span>        <span class="o">=</span> <span class="p">{</span><span class="mf">1411.7766</span><span class="p">},</span>
<span class="n">timestamp</span>     <span class="o">=</span> <span class="p">{</span><span class="n">Tue</span><span class="p">,</span> <span class="mi">10</span> <span class="n">Dec</span> <span class="mi">2019</span> <span class="mi">15</span><span class="p">:</span><span class="mi">37</span><span class="p">:</span><span class="mi">26</span> <span class="o">+</span><span class="mi">0100</span><span class="p">},</span>
<span class="n">biburl</span>        <span class="o">=</span> <span class="p">{</span><span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">dblp</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="n">rec</span><span class="o">/</span><span class="n">journals</span><span class="o">/</span><span class="n">corr</span><span class="o">/</span><span class="n">LiuLWT14</span><span class="o">.</span><span class="n">bib</span><span class="p">},</span>
<span class="n">bibsource</span>     <span class="o">=</span> <span class="p">{</span><span class="n">dblp</span> <span class="n">computer</span> <span class="n">science</span> <span class="n">bibliography</span><span class="p">,</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">dblp</span><span class="o">.</span><span class="n">org</span><span class="p">},</span>
<span class="n">howpublished</span>  <span class="o">=</span> <span class="p">{</span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">mmlab</span><span class="o">.</span><span class="n">ie</span><span class="o">.</span><span class="n">cuhk</span><span class="o">.</span><span class="n">edu</span><span class="o">.</span><span class="n">hk</span><span class="o">/</span><span class="n">projects</span><span class="o">/</span><span class="n">CelebA</span><span class="o">.</span><span class="n">html</span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">celeba_dataset_dir</span> <span class="o">=</span> <span class="s2">&quot;/path/to/celeba_dataset_directory&quot;</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Read 5 samples from CelebA dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">CelebADataset</span><span class="p">(</span><span class="n">dataset_dir</span><span class="o">=</span><span class="n">celeba_dataset_dir</span><span class="p">,</span> <span class="n">usage</span><span class="o">=</span><span class="s1">&#39;train&#39;</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Note: In celeba dataset, each data dictionary owns keys &quot;image&quot; and &quot;attr&quot;</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.dataset.CelebADataset.add_sampler">
<code class="sig-name descname">add_sampler</code><span class="sig-paren">(</span><em class="sig-param">new_sampler</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.add_sampler" title="Permalink to this definition">¶</a></dt>
<dd><p>为当前数据集对象添加采样器。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>new_sampler</strong> (Sampler) ：作用于当前数据集对象的采样器。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># use a DistributedSampler instead</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">new_sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">DistributedSampler</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span><span class="o">.</span><span class="n">add_sampler</span><span class="p">(</span><span class="n">new_sampler</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.apply">
<code class="sig-name descname">apply</code><span class="sig-paren">(</span><em class="sig-param">apply_func</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.apply" title="Permalink to this definition">¶</a></dt>
<dd><p>对数据集对象执行给定操作函数。</p>
<p><strong>参数：</strong></p>
<p><strong>apply_func</strong> (function)：数据集处理函数，要求该函数的输入是一个 <cite>Dataset</cite> 对象，返回的是处理后的 <cite>Dataset</cite> 对象。</p>
<p><strong>返回：</strong></p>
<p>执行了给定操作函数的数据集对象。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - <cite>apply_func</cite> 的类型不是函数。</p></li>
<li><p><strong>TypeError</strong> - <cite>apply_func</cite> 未返回Dataset对象。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Declare an apply_func function which returns a Dataset object</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">apply_func</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">data</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Use apply to call apply_func</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">apply_func</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.batch">
<code class="sig-name descname">batch</code><span class="sig-paren">(</span><em class="sig-param">batch_size</em>, <em class="sig-param">drop_remainder=False</em>, <em class="sig-param">num_parallel_workers=None</em>, <em class="sig-param">per_batch_map=None</em>, <em class="sig-param">input_columns=None</em>, <em class="sig-param">output_columns=None</em>, <em class="sig-param">column_order=None</em>, <em class="sig-param">pad_info=None</em>, <em class="sig-param">python_multiprocessing=False</em>, <em class="sig-param">max_rowsize=16</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.batch" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据集中连续 <cite>batch_size</cite> 条数据合并为一个批处理数据。</p>
<p><cite>batch</cite> 操作要求每列中的数据具有相同的shape。如果指定了参数 <cite>per_batch_map</cite> ，该参数将作用于批处理后的数据。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>执行 <cite>repeat</cite> 和 <cite>batch</cite> 操作的先后顺序，会影响批处理数据的数量及 <cite>per_batch_map</cite> 的结果。建议在 <cite>batch</cite> 操作完成后执行 <cite>repeat</cite> 操作。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>batch_size</strong> (Union[int, Callable]) - 指定每个批处理数据包含的数据条目。
如果 <cite>batch_size</cite> 为整型，则直接表示每个批处理数据大小；
如果为可调用对象，则可以通过自定义行为动态指定每个批处理数据大小，要求该可调用对象接收一个参数BatchInfo，返回一个整形代表批处理大小，用法请参考样例（3）。</p></li>
<li><p><strong>drop_remainder</strong> (bool, 可选) - 当最后一个批处理数据包含的数据条目小于 <cite>batch_size</cite> 时，是否将该批处理丢弃，不传递给下一个操作。默认值：False，不丢弃。</p></li>
<li><p><strong>num_parallel_workers</strong> (int, 可选) - 指定 <cite>batch</cite> 操作的并发进程数/线程数（由参数 <cite>python_multiprocessing</cite> 决定当前为多进程模式或多线程模式）。
默认值：None，使用mindspore.dataset.config中配置的线程数。</p></li>
<li><p><strong>per_batch_map</strong> (callable, 可选) - 可调用对象，以(list[Tensor], list[Tensor], …, BatchInfo)作为输入参数，处理后返回(list[Tensor], list[Tensor],…)作为新的数据列。
输入参数中每个list[Tensor]代表给定数据列中的一批Tensor，list[Tensor]的个数应与 <cite>input_columns</cite> 中传入列名的数量相匹配，
在返回的(list[Tensor], list[Tensor], …)中，list[Tensor]的个数应与输入相同，如果输出列数与输入列数不一致，则需要指定 <cite>output_columns</cite>。
该可调用对象的最后一个输入参数始终是BatchInfo，用于获取数据集的信息，用法参考样例（2）。</p></li>
<li><p><strong>input_columns</strong> (Union[str, list[str]], 可选)：指定 <cite>batch</cite> 操作的输入数据列。
如果 <cite>per_batch_map</cite> 不为None，列表中列名的个数应与 <cite>per_batch_map</cite> 中包含的列数匹配。默认值：None，不指定。</p></li>
<li><p><strong>output_columns</strong> (Union[str, list[str]], 可选) - 指定 <cite>batch</cite> 操作的输出数据列。如果输入数据列与输入数据列的长度不相等，则必须指定此参数。
此列表中列名的数量必须与 <cite>per_batch_map</cite> 方法的返回值数量相匹配。默认值：None，输出列将与输入列具有相同的名称。</p></li>
<li><p><strong>column_order</strong> (Union[str, list[str]], 可选) - 指定传递到下一个数据集操作的数据列顺序。
如果 <cite>input_column</cite> 长度不等于 <cite>output_column</cite> 长度，则此参数必须指定。
注意：列名不限定在 <cite>input_columns</cite> 和 <cite>output_columns</cite> 中指定的列，也可以是上一个操作输出的未被处理的数据列，详细可参阅使用样例（4）。默认值：None，按照原输入顺序排列。</p></li>
<li><p><strong>pad_info</strong> (dict, 可选) - 对给定数据列进行填充。通过传入dict来指定列信息与填充信息，例如 <cite>pad_info={“col1”:([224,224],0)}</cite> ，
则将列名为”col1”的数据列扩充到shape为[224,224]的Tensor，缺失的值使用0填充。默认值：None，不填充。</p></li>
<li><p><strong>python_multiprocessing</strong> (bool, 可选) - 启动Python多进程模式并行执行 <cite>per_batch_map</cite> 。如果 <cite>per_batch_map</cite> 的计算量很大，此选项可能会很有用。默认值：False，不启用多进程。</p></li>
<li><p><strong>max_rowsize</strong> (int, 可选) - 指定在多进程之间复制数据时，共享内存分配的最大空间，仅当 <cite>python_multiprocessing</cite> 为True时，该选项有效。默认值：16，单位为MB。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>Dataset， <cite>batch</cite> 操作后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where every 100 rows are combined into a batch</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># and drops the last incomplete batch if there is one.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># resize image according to its batch number, if it&#39;s 5-th batch, resize to (5^2, 5^2) = (25, 25)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">np_resize</span><span class="p">(</span><span class="n">col</span><span class="p">,</span> <span class="n">batchInfo</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">output</span> <span class="o">=</span> <span class="n">col</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">s</span> <span class="o">=</span> <span class="p">(</span><span class="n">batchInfo</span><span class="o">.</span><span class="n">get_batch_num</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span>
<span class="gp">... </span>    <span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">col</span><span class="p">:</span>
<span class="gp">... </span>        <span class="n">img</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">fromarray</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">&#39;uint8&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">&#39;RGB&#39;</span><span class="p">)</span>
<span class="gp">... </span>        <span class="n">img</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">resize</span><span class="p">((</span><span class="n">s</span><span class="p">,</span> <span class="n">s</span><span class="p">),</span> <span class="n">Image</span><span class="o">.</span><span class="n">ANTIALIAS</span><span class="p">)</span>
<span class="gp">... </span>        <span class="n">output</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">img</span><span class="p">)</span>
<span class="gp">... </span>        <span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="p">(</span><span class="n">output</span><span class="p">,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span><span class="n">batch_size</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">],</span> <span class="n">per_batch_map</span><span class="o">=</span><span class="n">np_resize</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.close_pool">
<code class="sig-name descname">close_pool</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.close_pool" title="Permalink to this definition">¶</a></dt>
<dd><p>关闭数据集对象中的多进程池。如果您熟悉多进程库，可以将此视为进程池对象的析构函数。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.concat">
<code class="sig-name descname">concat</code><span class="sig-paren">(</span><em class="sig-param">datasets</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.concat" title="Permalink to this definition">¶</a></dt>
<dd><p>对传入的多个数据集对象进行拼接操作，也可以使用”+”运算符来进行数据集进行拼接。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>用于拼接的多个数据集对象，每个数据集对象的列名、每列数据的维度（rank）和数据类型必须相同。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>datasets</strong> (Union[list, Dataset]) - 与当前数据集对象拼接的数据集对象列表或单个数据集对象。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>Dataset，拼接后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset by concatenating dataset_1 and dataset_2 with &quot;+&quot; operator</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset_1</span> <span class="o">+</span> <span class="n">dataset_2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset by concatenating dataset_1 and dataset_2 with concat operation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset_1</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">dataset_2</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.create_dict_iterator">
<code class="sig-name descname">create_dict_iterator</code><span class="sig-paren">(</span><em class="sig-param">num_epochs=-1</em>, <em class="sig-param">output_numpy=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.create_dict_iterator" title="Permalink to this definition">¶</a></dt>
<dd><p>基于数据集对象创建迭代器，输出的数据为字典类型。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>num_epochs</strong> (int, 可选) - 迭代器可以迭代的最大次数。默认值：-1，迭代器可以迭代无限次。</p></li>
<li><p><strong>output_numpy</strong> (bool, 可选) - 输出的数据是否转为NumPy类型。如果为False，迭代器输出的每列数据类型为MindSpore.Tensor，否则为NumPy。默认值：False。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>DictIterator，基于数据集对象创建的字典迭代器。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">iterator</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">create_dict_iterator</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">iterator</span><span class="p">:</span>
<span class="gp">... </span>    <span class="c1"># item is a dict</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
<span class="gp">... </span>    <span class="k">break</span>
<span class="go">&lt;class &#39;dict&#39;&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.create_tuple_iterator">
<code class="sig-name descname">create_tuple_iterator</code><span class="sig-paren">(</span><em class="sig-param">columns=None</em>, <em class="sig-param">num_epochs=-1</em>, <em class="sig-param">output_numpy=False</em>, <em class="sig-param">do_copy=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.create_tuple_iterator" title="Permalink to this definition">¶</a></dt>
<dd><p>基于数据集对象创建迭代器，输出数据为ndarray组成的列表。</p>
<p>可以通过参数 <cite>columns</cite> 指定输出的所有列名及列的顺序。如果columns未指定，列的顺序将保持不变。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>columns</strong> (list[str], 可选) - 用于指定输出的数据列和列的顺序。默认值：None，输出所有数据列。</p></li>
<li><p><strong>num_epochs</strong> (int, 可选) - 迭代器可以迭代的最大次数。默认值：-1，迭代器可以迭代无限次。</p></li>
<li><p><strong>output_numpy</strong> (bool, 可选) - 输出的数据是否转为NumPy类型。如果为False，迭代器输出的每列数据类型为MindSpore.Tensor，否则为NumPy。默认值：False。</p></li>
<li><p><strong>do_copy</strong> (bool, 可选) - 当参数 <cite>output_numpy</cite> 为False，即输出数据类型为mindspore.Tensor时，可以将此参数指定为False以减少拷贝，获得更好的性能。默认值：True。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>TupleIterator，基于数据集对象创建的元组迭代器。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">iterator</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">create_tuple_iterator</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">iterator</span><span class="p">:</span>
<span class="gp">... </span>    <span class="c1"># item is a list</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
<span class="gp">... </span>    <span class="k">break</span>
<span class="go">&lt;class &#39;list&#39;&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.device_que">
<code class="sig-name descname">device_que</code><span class="sig-paren">(</span><em class="sig-param">send_epoch_end=True</em>, <em class="sig-param">create_data_info_queue=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.device_que" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据异步传输到Ascend/GPU设备上。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>send_epoch_end</strong> (bool, 可选) - 数据发送完成后是否发送结束标识到设备上，默认值：True。</p></li>
<li><p><strong>create_data_info_queue</strong> (bool, 可选) - 是否创建一个队列，用于存储每条数据的数据类型和shape。默认值：False，不创建。</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>如果设备类型为Ascend，每次传输的数据大小限制为256MB。</p>
</div>
<p><strong>返回：</strong></p>
<p>Dataset，用于帮助发送数据到设备上的数据集对象。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.dynamic_min_max_shapes">
<code class="sig-name descname">dynamic_min_max_shapes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.dynamic_min_max_shapes" title="Permalink to this definition">¶</a></dt>
<dd><p>当数据集对象中的数据shape不唯一（动态shape）时，获取数据的最小shape和最大shape。</p>
<p><strong>返回：</strong></p>
<p>两个列表代表最小shape和最大shape，每个列表中的shape按照数据列的顺序排列。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">generator1</span><span class="p">():</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">16</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">83</span><span class="p">)),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">GeneratorDataset</span><span class="p">(</span><span class="n">generator1</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;data1&quot;</span><span class="p">,</span> <span class="s2">&quot;data2&quot;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span><span class="o">.</span><span class="n">set_dynamic_columns</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;data1&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">16</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">83</span><span class="p">],</span> <span class="s2">&quot;data2&quot;</span><span class="p">:</span> <span class="p">[]})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">min_shapes</span><span class="p">,</span> <span class="n">max_shapes</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">dynamic_min_max_shapes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.filter">
<code class="sig-name descname">filter</code><span class="sig-paren">(</span><em class="sig-param">predicate</em>, <em class="sig-param">input_columns=None</em>, <em class="sig-param">num_parallel_workers=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.filter" title="Permalink to this definition">¶</a></dt>
<dd><p>通过自定义判断条件对数据集对象中的数据进行过滤。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>predicate</strong> (callable) - Python可调用对象。要求该对象接收n个入参，用于指代每个数据列的数据，最后返回值一个bool值。
如果返回值为False，则表示过滤掉该条数据。注意n的值与参数 <cite>input_columns</cite> 表示的输入列数量一致。</p></li>
<li><p><strong>input_columns</strong> (Union[str, list[str]], 可选) - <cite>filter</cite> 操作的输入数据列。默认值：None，<cite>predicate</cite> 将应用于数据集中的所有列。</p></li>
<li><p><strong>num_parallel_workers</strong> (int, 可选) - 指定 <cite>filter</cite> 操作的并发线程数。默认值：None，使用mindspore.dataset.config中配置的线程数。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>Dataset，执行给定筛选过滤操作的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># generator data(0 ~ 63)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># filter the data that greater than or equal to 11</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">predicate</span><span class="o">=</span><span class="k">lambda</span> <span class="n">data</span><span class="p">:</span> <span class="n">data</span> <span class="o">&lt;</span> <span class="mi">11</span><span class="p">,</span> <span class="n">input_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.flat_map">
<code class="sig-name descname">flat_map</code><span class="sig-paren">(</span><em class="sig-param">func</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.flat_map" title="Permalink to this definition">¶</a></dt>
<dd><p>对数据集对象中每一条数据执行给定的数据处理，并将结果展平。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>func</strong> (function) - 数据处理函数，要求输入必须为一个’ndarray’，返回值是一个’Dataset’对象。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>执行给定操作后的数据集对象。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - <cite>func</cite> 不是函数。</p></li>
<li><p><strong>TypeError</strong> - <cite>func</cite> 的返回值不是数据集对象。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># use NumpySlicesDataset as an example</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">NumpySlicesDataset</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">flat_map_func</span><span class="p">(</span><span class="n">array</span><span class="p">):</span>
<span class="gp">... </span>    <span class="c1"># create a NumpySlicesDataset with the array</span>
<span class="gp">... </span>    <span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">NumpySlicesDataset</span><span class="p">(</span><span class="n">array</span><span class="p">)</span>
<span class="gp">... </span>    <span class="c1"># repeat the dataset twice</span>
<span class="gp">... </span>    <span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">dataset</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">flat_map</span><span class="p">(</span><span class="n">flat_map_func</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># [[0, 1], [0, 1], [2, 3], [2, 3]]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.get_batch_size">
<code class="sig-name descname">get_batch_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.get_batch_size" title="Permalink to this definition">¶</a></dt>
<dd><p>获得数据集对象定义的批处理大小，即一个批处理数据中包含的数据条数。</p>
<p><strong>返回：</strong></p>
<p>int，一个批处理数据中包含的数据条数。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">batch_size</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">get_batch_size</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.get_class_indexing">
<code class="sig-name descname">get_class_indexing</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.get_class_indexing" title="Permalink to this definition">¶</a></dt>
<dd><p>返回类别索引。</p>
<p><strong>返回：</strong></p>
<p>dict，描述类别名称到索引的键值对映射关系，通常为str-to-int格式。针对COCO数据集，类别名称到索引映射关系描述形式为str-to-list&lt;int&gt;格式，列表中的第二个数字表示超级类别。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">class_indexing</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">get_class_indexing</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.get_col_names">
<code class="sig-name descname">get_col_names</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.get_col_names" title="Permalink to this definition">¶</a></dt>
<dd><p>返回数据集对象中包含的列名。</p>
<p><strong>返回：</strong></p>
<p>list，数据集中所有列名组成列表。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">col_names</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">get_col_names</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.get_dataset_size">
<code class="sig-name descname">get_dataset_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.get_dataset_size" title="Permalink to this definition">¶</a></dt>
<dd><p>返回一个epoch中的batch数。</p>
<p><strong>返回：</strong></p>
<p>int，batch的数目。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset_size</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">get_dataset_size</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.get_repeat_count">
<code class="sig-name descname">get_repeat_count</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.get_repeat_count" title="Permalink to this definition">¶</a></dt>
<dd><p>获取 <cite>RepeatDataset</cite> 中定义的repeat操作的次数。默认值：1。</p>
<p><strong>返回：</strong></p>
<p>int，repeat操作的次数。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repeat_count</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">get_repeat_count</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.input_indexs">
<em class="property">property </em><code class="sig-name descname">input_indexs</code><a class="headerlink" href="#mindspore.dataset.CelebADataset.input_indexs" title="Permalink to this definition">¶</a></dt>
<dd><p>获取input index信息。</p>
<p><strong>返回：</strong></p>
<p>input index信息的元组。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># set input_indexs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span><span class="o">.</span><span class="n">input_indexs</span> <span class="o">=</span> <span class="mi">10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dataset</span><span class="o">.</span><span class="n">input_indexs</span><span class="p">)</span>
<span class="go">10</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.map">
<code class="sig-name descname">map</code><span class="sig-paren">(</span><em class="sig-param">operations</em>, <em class="sig-param">input_columns=None</em>, <em class="sig-param">output_columns=None</em>, <em class="sig-param">column_order=None</em>, <em class="sig-param">num_parallel_workers=None</em>, <em class="sig-param">python_multiprocessing=False</em>, <em class="sig-param">cache=None</em>, <em class="sig-param">callbacks=None</em>, <em class="sig-param">max_rowsize=16</em>, <em class="sig-param">offload=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.map" title="Permalink to this definition">¶</a></dt>
<dd><p>给定一组数据增强列表，按顺序将数据增强作用在数据集对象上。</p>
<p>每个数据增强操作将数据集对象中的一个或多个数据列作为输入，将数据增强的结果输出为一个或多个数据列。
第一个数据增强操作将 <cite>input_columns</cite> 中指定的列作为输入。
如果数据增强列表中存在多个数据增强操作，则上一个数据增强的输出列将作为下一个数据增强的输入列。</p>
<p>最后一个数据增强的输出列的列名由 <cite>output_columns</cite> 指定，如果没有指定 <cite>output_columns</cite> ，输出列名与 <cite>input_columns</cite> 一致。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>operations</strong> (Union[list[TensorOp], list[functions]]) - 一组数据增强操作，支持数据集增强算子或者用户自定义的Python Callable对象。map操作将按顺序将一组数据增强作用在数据集对象上。</p></li>
<li><p><strong>input_columns</strong> (Union[str, list[str]], 可选) - 第一个数据增强操作的输入数据列。此列表的长度必须与 <cite>operations</cite> 列表中第一个数据增强的预期输入列数相匹配。默认值：None。表示所有数据列都将传递给第一个数据增强操作。</p></li>
<li><p><strong>output_columns</strong> (Union[str, list[str]], 可选) - 最后一个数据增强操作的输出数据列。如果 <cite>input_columns</cite> 长度不等于 <cite>output_columns</cite> 长度，则必须指定此参数。列表的长度必须必须与最后一个数据增强的输出列数相匹配。默认值：None，输出列将与输入列具有相同的名称。</p></li>
<li><p><strong>column_order</strong> (Union[str, list[str]], 可选) - 指定传递到下一个数据集操作的数据列的顺序。如果 <cite>input_columns</cite> 长度不等于 <cite>output_columns</cite> 长度，则必须指定此参数。 注意：参数的列名不限定在 <cite>input_columns</cite> 和 <cite>output_columns</cite> 中指定的列，也可以是上一个操作输出的未被处理的数据列。默认值：None，按照原输入顺序排列。</p></li>
<li><p><strong>num_parallel_workers</strong> (int, 可选) - 指定map操作的多进程/多线程并发数，加快处理速度。默认值：None，将使用 <cite>set_num_parallel_workers</cite> 设置的并发数。</p></li>
<li><p><strong>python_multiprocessing</strong> (bool, 可选) - 启用Python多进程模式加速map操作。当传入的 <cite>operations</cite> 计算量很大时，开启此选项可能会有较好效果。默认值：False。</p></li>
<li><p><strong>cache</strong> (DatasetCache, 可选) - 单节点数据缓存服务，用于加快数据集处理，详情请阅读 <a class="reference external" href="https://www.mindspore.cn/docs/programming_guide/zh-CN/master/cache.html">单节点数据缓存</a> 。默认值：None，不使用缓存。</p></li>
<li><p><strong>callbacks</strong> (DSCallback, list[DSCallback], 可选) - 要调用的Dataset回调函数列表。默认值：None。</p></li>
<li><p><strong>max_rowsize</strong> (int, 可选) - 指定在多进程之间复制数据时，共享内存分配的最大空间，仅当 <cite>python_multiprocessing</cite> 为True时，该选项有效。默认值：16，单位为MB。</p></li>
<li><p><strong>offload</strong> (bool, 可选) - 是否进行异构硬件加速，详情请阅读 <a class="reference external" href="https://www.mindspore.cn/docs/programming_guide/zh-CN/master/enable_dataset_offload.html">数据准备异构加速</a> 。默认值：None。</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p><cite>operations</cite> 参数主要接收 <cite>mindspore.dataset</cite> 模块中c_transforms、py_transforms算子，以及用户定义的Python函数(PyFuncs)。</p></li>
<li><p>不要将 <cite>mindspore.nn</cite> 和 <cite>mindspore.ops</cite> 或其他的网络计算算子添加到 <cite>operations</cite> 中。</p></li>
</ul>
</div>
<p><strong>返回：</strong></p>
<p>MapDataset，map操作后的数据集。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance of Dataset which has 2 columns, &quot;image&quot; and &quot;label&quot;.</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Define two operations, where each operation accepts 1 input column and outputs 1 column.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">decode_op</span> <span class="o">=</span> <span class="n">c_vision</span><span class="o">.</span><span class="n">Decode</span><span class="p">(</span><span class="n">rgb</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">random_jitter_op</span> <span class="o">=</span> <span class="n">c_vision</span><span class="o">.</span><span class="n">RandomColorAdjust</span><span class="p">(</span><span class="n">brightness</span><span class="o">=</span><span class="p">(</span><span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">),</span> <span class="n">contrast</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
<span class="gp">... </span>                                              <span class="n">saturation</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">hue</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># 1) Simple map example.</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Apply decode_op on column &quot;image&quot;. This column will be replaced by the outputted</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># column of decode_op. Since column_order is not provided, both columns &quot;image&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># and &quot;label&quot; will be propagated to the child node in their original order.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Decode and rename column &quot;image&quot; to &quot;decoded_image&quot;.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">],</span> <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;decoded_image&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Specify the order of the output columns.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">output_columns</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">column_order</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">,</span> <span class="s2">&quot;image&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Rename column &quot;image&quot; to &quot;decoded_image&quot; and also specify the order of the output columns.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;decoded_image&quot;</span><span class="p">],</span> <span class="n">column_order</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">,</span> <span class="s2">&quot;decoded_image&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Rename column &quot;image&quot; to &quot;decoded_image&quot; and keep only this column.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;decoded_image&quot;</span><span class="p">],</span> <span class="n">column_order</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;decoded_image&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># A simple example for mapping pyfunc. Renaming columns and specifying column order</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># work in the same way as the previous examples.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">NumpySlicesDataset</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]],</span> <span class="n">column_names</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># 2) Map example with more than one operation.</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where the images are decoded, then randomly color jittered.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># decode_op takes column &quot;image&quot; as input and outputs one column. The column</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># outputted by decode_op is passed as input to random_jitter_op.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># random_jitter_op will output one column. Column &quot;image&quot; will be replaced by</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># the column outputted by random_jitter_op (the very last operation). All other</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># columns are unchanged. Since column_order is not specified, the order of the</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># columns will remain the same.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">,</span> <span class="n">random_jitter_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Rename the column outputted by random_jitter_op to &quot;image_mapped&quot;.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Specifying column order works in the same way as examples in 1).</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">decode_op</span><span class="p">,</span> <span class="n">random_jitter_op</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;image_mapped&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Map with multiple operations using pyfunc. Renaming columns and specifying column order</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># work in the same way as examples in 1).</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">NumpySlicesDataset</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]],</span> <span class="n">column_names</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">*</span> <span class="n">x</span><span class="p">),</span> <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">],</span>
<span class="gp">... </span>                                  <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;data_mapped&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># 3) Example where number of input columns is not equal to number of output columns.</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># operations[0] is a lambda that takes 2 columns as input and outputs 3 columns.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># operations[1] is a lambda that takes 3 columns as input and outputs 1 column.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># operations[2] is a lambda that takes 1 column as input and outputs 4 columns.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Note: The number of output columns of operation[i] must equal the number of</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># input columns of operation[i+1]. Otherwise, this map call will also result</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># in an error.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operations</span> <span class="o">=</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)),</span>
<span class="gp">... </span>              <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">:</span> <span class="n">x</span> <span class="o">*</span> <span class="n">y</span> <span class="o">*</span> <span class="n">z</span><span class="p">),</span>
<span class="gp">... </span>              <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="p">(</span><span class="n">x</span> <span class="o">%</span> <span class="mi">2</span><span class="p">,</span> <span class="n">x</span> <span class="o">%</span> <span class="mi">3</span><span class="p">,</span> <span class="n">x</span> <span class="o">%</span> <span class="mi">5</span><span class="p">,</span> <span class="n">x</span> <span class="o">%</span> <span class="mi">7</span><span class="p">))]</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Note: Since the number of input columns is not the same as the number of</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># output columns, the output_columns and column_order parameters must be</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># specified. Otherwise, this map call will also result in an error.</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">NumpySlicesDataset</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]],</span> <span class="p">[[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]]),</span> <span class="n">column_names</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Propagate all columns to the child node in this order:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="p">,</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;mod2&quot;</span><span class="p">,</span> <span class="s2">&quot;mod3&quot;</span><span class="p">,</span> <span class="s2">&quot;mod5&quot;</span><span class="p">,</span> <span class="s2">&quot;mod7&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">column_order</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;mod2&quot;</span><span class="p">,</span> <span class="s2">&quot;mod3&quot;</span><span class="p">,</span> <span class="s2">&quot;mod5&quot;</span><span class="p">,</span> <span class="s2">&quot;mod7&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Propagate some columns to the child node in this order:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="p">,</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">output_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;mod2&quot;</span><span class="p">,</span> <span class="s2">&quot;mod3&quot;</span><span class="p">,</span> <span class="s2">&quot;mod5&quot;</span><span class="p">,</span> <span class="s2">&quot;mod7&quot;</span><span class="p">],</span>
<span class="gp">... </span>                      <span class="n">column_order</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;mod7&quot;</span><span class="p">,</span> <span class="s2">&quot;mod3&quot;</span><span class="p">,</span> <span class="s2">&quot;col2&quot;</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.num_classes">
<code class="sig-name descname">num_classes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.num_classes" title="Permalink to this definition">¶</a></dt>
<dd><p>获取数据集对象中所有样本的类别数目。</p>
<p><strong>返回：</strong></p>
<p>int，类别的数目。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">num_classes</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">num_classes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.output_shapes">
<code class="sig-name descname">output_shapes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.output_shapes" title="Permalink to this definition">¶</a></dt>
<dd><p>获取数据集对象中每列数据的shape。</p>
<p><strong>返回：</strong></p>
<p>list，每列数据的shape列表。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output_shapes</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">output_shapes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.output_types">
<code class="sig-name descname">output_types</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.output_types" title="Permalink to this definition">¶</a></dt>
<dd><p>获取数据集对象中每列数据的数据类型。</p>
<p><strong>返回：</strong></p>
<p>list，每列数据的数据类型列表。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output_types</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">output_types</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.project">
<code class="sig-name descname">project</code><span class="sig-paren">(</span><em class="sig-param">columns</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.project" title="Permalink to this definition">¶</a></dt>
<dd><p>从数据集对象中选择需要的列，并按给定的列名的顺序进行排序，
未指定的数据列将被丢弃。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>columns</strong> (Union[str, list[str]]) - 要选择的数据列的列名列表。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>ProjectDataset，project操作后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">columns_to_project</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;column3&quot;</span><span class="p">,</span> <span class="s2">&quot;column1&quot;</span><span class="p">,</span> <span class="s2">&quot;column2&quot;</span><span class="p">]</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset that consists of column3, column1, column2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># in that order, regardless of the original order of columns.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">project</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">columns_to_project</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.rename">
<code class="sig-name descname">rename</code><span class="sig-paren">(</span><em class="sig-param">input_columns</em>, <em class="sig-param">output_columns</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.rename" title="Permalink to this definition">¶</a></dt>
<dd><p>对数据集对象按指定的列名进行重命名。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>input_columns</strong> (Union[str, list[str]]) - 待重命名的列名列表。</p></li>
<li><p><strong>output_columns</strong> (Union[str, list[str]]) - 重命名后的列名列表。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>RenameDataset，rename操作后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">input_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;input_col1&quot;</span><span class="p">,</span> <span class="s2">&quot;input_col2&quot;</span><span class="p">,</span> <span class="s2">&quot;input_col3&quot;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;output_col1&quot;</span><span class="p">,</span> <span class="s2">&quot;output_col2&quot;</span><span class="p">,</span> <span class="s2">&quot;output_col3&quot;</span><span class="p">]</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where input_col1 is renamed to output_col1, and</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># input_col2 is renamed to output_col2, and input_col3 is renamed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># to output_col3.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">input_columns</span><span class="o">=</span><span class="n">input_columns</span><span class="p">,</span> <span class="n">output_columns</span><span class="o">=</span><span class="n">output_columns</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.repeat">
<code class="sig-name descname">repeat</code><span class="sig-paren">(</span><em class="sig-param">count=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.repeat" title="Permalink to this definition">¶</a></dt>
<dd><p>重复此数据集 <cite>count</cite> 次。如果 <cite>count</cite> 为None或-1，则无限重复。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>repeat和batch的顺序反映了batch的数量。建议：repeat操作在batch操作之后使用。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>count</strong> (int) - 数据集重复的次数。默认值：None。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>RepeatDataset，repeat操作后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where the dataset is repeated for 50 epochs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where each epoch is shuffled individually</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where the dataset is first repeated for</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># 50 epochs before shuffling. The shuffle operator will treat</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># the entire 50 epochs as one big dataset.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.reset">
<code class="sig-name descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.reset" title="Permalink to this definition">¶</a></dt>
<dd><p>重置下一个epoch的数据集对象。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.save">
<code class="sig-name descname">save</code><span class="sig-paren">(</span><em class="sig-param">file_name</em>, <em class="sig-param">num_files=1</em>, <em class="sig-param">file_type='mindrecord'</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.save" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据处理管道中正处理的数据保存为通用的数据集格式。支持的数据集格式：’mindrecord’。</p>
<p>将数据保存为’mindrecord’格式时存在隐式类型转换。转换表展示如何执行类型转换。</p>
<table class="colwidths-given docutils align-default" id="id5">
<caption><span class="caption-text">保存为’mindrecord’格式时的隐式类型转换</span><a class="headerlink" href="#id5" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>‘dataset’类型</p></th>
<th class="head"><p>‘mindrecord’类型</p></th>
<th class="head"><p>说明</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>bool</p></td>
<td><p>None</p></td>
<td><p>不支持</p></td>
</tr>
<tr class="row-odd"><td><p>int8</p></td>
<td><p>int32</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>uint8</p></td>
<td><p>bytes</p></td>
<td><p>丢失维度信息</p></td>
</tr>
<tr class="row-odd"><td><p>int16</p></td>
<td><p>int32</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>uint16</p></td>
<td><p>int32</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>int32</p></td>
<td><p>int32</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>uint32</p></td>
<td><p>int64</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>int64</p></td>
<td><p>int64</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>uint64</p></td>
<td><p>None</p></td>
<td><p>不支持</p></td>
</tr>
<tr class="row-odd"><td><p>float16</p></td>
<td><p>float32</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>float32</p></td>
<td><p>float32</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>float64</p></td>
<td><p>float64</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>string</p></td>
<td><p>string</p></td>
<td><p>不支持多维字符串</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ol class="arabic simple">
<li><p>如需按顺序保存数据，将数据集的 <cite>shuffle</cite> 设置为False，将 <cite>num_files</cite> 设置为1。</p></li>
<li><p>在执行保存操作之前，不要使用batch操作、repeat操作或具有随机属性的数据增强的map操作。</p></li>
<li><p>当数据的维度可变时，只支持1维数组或者在第0维变化的多维数组。</p></li>
<li><p>不支持UINT64类型、多维的UINT8类型、多维STRING类型。</p></li>
</ol>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>file_name</strong> (str) - 数据集文件的路径。</p></li>
<li><p><strong>num_files</strong> (int, 可选) - 数据集文件的数量，默认值：1。</p></li>
<li><p><strong>file_type</strong> (str, 可选) - 数据集格式，默认值：’mindrecord’。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.set_dynamic_columns">
<code class="sig-name descname">set_dynamic_columns</code><span class="sig-paren">(</span><em class="sig-param">columns=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.set_dynamic_columns" title="Permalink to this definition">¶</a></dt>
<dd><p>设置数据集的动态shape信息，需要在定义好完整的数据处理管道后进行设置。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>columns</strong> (dict) - 包含数据集中每列shape信息的字典。shape[i]为 <cite>None</cite> 表示shape[i]的数据长度是动态的。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">generator1</span><span class="p">():</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">16</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">83</span><span class="p">)),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">GeneratorDataset</span><span class="p">(</span><span class="n">generator1</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;data1&quot;</span><span class="p">,</span> <span class="s2">&quot;data2&quot;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span><span class="o">.</span><span class="n">set_dynamic_columns</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;data1&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">16</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">83</span><span class="p">],</span> <span class="s2">&quot;data2&quot;</span><span class="p">:</span> <span class="p">[]})</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.shuffle">
<code class="sig-name descname">shuffle</code><span class="sig-paren">(</span><em class="sig-param">buffer_size</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.shuffle" title="Permalink to this definition">¶</a></dt>
<dd><p>使用以下策略混洗此数据集的行：</p>
<ol class="arabic simple">
<li><p>生成一个混洗缓冲区包含 <cite>buffer_size</cite> 条数据行。</p></li>
<li><p>从混洗缓冲区中随机选择一个数据行，传递给下一个操作。</p></li>
<li><p>从上一个操作获取下一个数据行（如果有的话），并将其放入混洗缓冲区中。</p></li>
<li><p>重复步骤2和3，直到混洗缓冲区中没有数据行为止。</p></li>
</ol>
<p>在第一个epoch中可以通过 <cite>dataset.config.set_seed</cite> 来设置随机种子，在随后的每个epoch，种子都会被设置成一个新产生的随机值。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>buffer_size</strong> (int) - 用于混洗的缓冲区大小（必须大于1）。将 <cite>buffer_size</cite> 设置为数据集大小将进行全局混洗。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>ShuffleDataset，混洗后的数据集对象。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>RuntimeError</strong> - 混洗前存在通过 <cite>dataset.sync_wait</cite> 进行同步操作。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Optionally set the seed for the first epoch</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">set_seed</span><span class="p">(</span><span class="mi">58</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a shuffled dataset using a shuffle buffer of size 4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.skip">
<code class="sig-name descname">skip</code><span class="sig-paren">(</span><em class="sig-param">count</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.skip" title="Permalink to this definition">¶</a></dt>
<dd><p>跳过此数据集对象的前 <cite>count</cite> 条数据。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>count</strong> (int) - 要跳过数据的条数。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>SkipDataset，跳过指定条数据后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset which skips first 3 elements from data</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">skip</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.split">
<code class="sig-name descname">split</code><span class="sig-paren">(</span><em class="sig-param">sizes</em>, <em class="sig-param">randomize=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.split" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据集拆分为多个不重叠的子数据集。</p>
<p><strong>参数：</strong></p>
<ul>
<li><p><strong>sizes</strong> (Union[list[int], list[float]]) - 如果指定了一列整数[s1, s2, …, sn]，数据集将被拆分为n个大小为s1、s2、…、sn的数据集。如果所有输入大小的总和不等于原始数据集大小，则报错。如果指定了一列浮点数[f1, f2, …, fn]，则所有浮点数必须介于0和1之间，并且总和必须为1，否则报错。数据集将被拆分为n个大小为round(f1*K)、round(f2*K)、…、round(fn*K)的数据集，其中K是原始数据集的大小。</p>
<p>如果round四舍五入计算后：</p>
<ul class="simple">
<li><p>任何子数据集的的大小等于0，都将发生错误。</p></li>
<li><p>如果子数据集大小的总和小于K，K - sigma(round(fi * k))的值将添加到第一个子数据集，sigma为求和操作。</p></li>
<li><p>如果子数据集大小的总和大于K，sigma(round(fi * K)) - K的值将从第一个足够大的子数据集中删除，且删除后的子数据集大小至少大于1。</p></li>
</ul>
</li>
<li><p><strong>randomize</strong> (bool, 可选) - 确定是否随机拆分数据，默认值：True，数据集将被随机拆分。否则将按顺序拆分为多个不重叠的子数据集。</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ol class="arabic simple">
<li><p>如果进行拆分操作的数据集对象为MappableDataset类型，则将自动调用一个优化后的split操作。</p></li>
<li><p>如果进行split操作，则不应对数据集对象进行分片操作（如指定num_shards或使用DistributerSampler）。相反，如果创建一个DistributerSampler，并在split操作拆分后的子数据集对象上进行分片操作，强烈建议在每个子数据集上设置相同的种子，否则每个分片可能不是同一个子数据集的一部分（请参见示例）。</p></li>
<li><p>强烈建议不要对数据集进行混洗，而是使用随机化（randomize=True）。对数据集进行混洗的结果具有不确定性，每个拆分后的子数据集中的数据在每个epoch可能都不同。</p></li>
</ol>
</div>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>RuntimeError</strong> - 数据集对象不支持 <cite>get_dataset_size</cite> 或者 <cite>get_dataset_size</cite> 返回None。</p></li>
<li><p><strong>RuntimeError</strong> - sizes是整数列表，并且size中所有元素的总和不等于数据集大小。</p></li>
<li><p><strong>RuntimeError</strong> - sizes是float列表，并且计算后存在大小为0的拆分子数据集。</p></li>
<li><p><strong>RuntimeError</strong> - 数据集对象在调用拆分之前已进行分片。</p></li>
<li><p><strong>ValueError</strong> - sizes是float列表，且并非所有float数都在0和1之间，或者float数的总和不等于1。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>tuple(Dataset)，split操作后子数据集对象的元组。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Since many datasets have shuffle on by default, set shuffle to False if split will be called!</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">ImageFolderDataset</span><span class="p">(</span><span class="n">image_folder_dataset_dir</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Set the seed, and tell split to use this seed when randomizing.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This is needed because sharding will be done later</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">set_seed</span><span class="p">(</span><span class="mi">58</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_dataset</span><span class="p">,</span> <span class="n">test_dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">split</span><span class="p">([</span><span class="mf">0.9</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># To shard the train dataset, use a DistributedSampler</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">DistributedSampler</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_dataset</span><span class="o">.</span><span class="n">use_sampler</span><span class="p">(</span><span class="n">train_sampler</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.sync_update">
<code class="sig-name descname">sync_update</code><span class="sig-paren">(</span><em class="sig-param">condition_name</em>, <em class="sig-param">num_batch=None</em>, <em class="sig-param">data=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.sync_update" title="Permalink to this definition">¶</a></dt>
<dd><p>释放阻塞条件并使用给定数据触发回调函数。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>condition_name</strong> (str) - 用于触发发送下一个数据行的条件名称。</p></li>
<li><p><strong>num_batch</strong> (Union[int, None]) - 释放的batch（row）数。当 <cite>num_batch</cite> 为None时，将默认为 <cite>sync_wait</cite>  操作指定的值，默认值：None。</p></li>
<li><p><strong>data</strong> (Any) - 用户自定义传递给回调函数的数据，默认值：None。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.sync_wait">
<code class="sig-name descname">sync_wait</code><span class="sig-paren">(</span><em class="sig-param">condition_name</em>, <em class="sig-param">num_batch=1</em>, <em class="sig-param">callback=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.sync_wait" title="Permalink to this definition">¶</a></dt>
<dd><p>为同步操作在数据集对象上添加阻塞条件。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>condition_name</strong> (str) - 用于触发发送下一行数据的条件名称。</p></li>
<li><p><strong>num_batch</strong> (int) - 每个epoch开始时无阻塞的batch数。</p></li>
<li><p><strong>callback</strong> (function) -  <cite>sync_update</cite> 操作中将调用的回调函数。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>SyncWaitDataset，添加了阻塞条件的数据集对象。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>RuntimeError</strong> - 条件名称已存在。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">gen</span><span class="p">():</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">100</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">i</span><span class="p">),)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Augment</span><span class="p">:</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">loss</span><span class="p">):</span>
<span class="gp">... </span>        <span class="bp">self</span><span class="o">.</span><span class="n">loss</span> <span class="o">=</span> <span class="n">loss</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">preprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">input_</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="n">input_</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="gp">... </span>        <span class="bp">self</span><span class="o">.</span><span class="n">loss</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;loss&quot;</span><span class="p">]</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">batch_size</span> <span class="o">=</span> <span class="mi">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">GeneratorDataset</span><span class="p">(</span><span class="n">gen</span><span class="p">,</span> <span class="n">column_names</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;input&quot;</span><span class="p">])</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">aug</span> <span class="o">=</span> <span class="n">Augment</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">sync_wait</span><span class="p">(</span><span class="n">condition_name</span><span class="o">=</span><span class="s2">&quot;policy&quot;</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">aug</span><span class="o">.</span><span class="n">update</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">operations</span><span class="o">=</span><span class="p">[</span><span class="n">aug</span><span class="o">.</span><span class="n">preprocess</span><span class="p">],</span> <span class="n">input_columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;input&quot;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">batch</span><span class="p">(</span><span class="n">batch_size</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">dataset</span><span class="o">.</span><span class="n">create_dict_iterator</span><span class="p">(</span><span class="n">num_epochs</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">output_numpy</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">assert</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;input&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">count</span>
<span class="gp">... </span>    <span class="n">count</span> <span class="o">+=</span> <span class="n">batch_size</span>
<span class="gp">... </span>    <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;loss&quot;</span><span class="p">:</span> <span class="n">count</span><span class="p">}</span>
<span class="gp">... </span>    <span class="n">dataset</span><span class="o">.</span><span class="n">sync_update</span><span class="p">(</span><span class="n">condition_name</span><span class="o">=</span><span class="s2">&quot;policy&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.take">
<code class="sig-name descname">take</code><span class="sig-paren">(</span><em class="sig-param">count=-1</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.take" title="Permalink to this definition">¶</a></dt>
<dd><p>从数据集中获取最多 <cite>count</cite> 的元素。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ol class="arabic simple">
<li><p>如果 <cite>count</cite> 大于数据集中的数据条数或等于-1，则取数据集中的所有数据。</p></li>
<li><p>take和batch操作顺序很重要，如果take在batch操作之前，则取给定条数，否则取给定batch数。</p></li>
</ol>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>count</strong> (int, 可选) - 要从数据集对象中获取的数据条数，默认值：-1，获取所有数据。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>TakeDataset，take操作后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset where the dataset includes 50 elements.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.to_device">
<code class="sig-name descname">to_device</code><span class="sig-paren">(</span><em class="sig-param">send_epoch_end=True</em>, <em class="sig-param">create_data_info_queue=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.to_device" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据从CPU传输到GPU、Ascend或其他设备。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>send_epoch_end</strong> (bool, 可选) - 是否将epoch结束符 <cite>end_of_sequence</cite> 发送到设备，默认值：True。</p></li>
<li><p><strong>create_data_info_queue</strong> (bool, 可选) - 是否创建存储数据类型和shape的队列，默认值：False。</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>如果设备为Ascend，则逐个传输数据。每次数据传输的限制为256M。</p>
</div>
<p><strong>返回：</strong></p>
<p>TransferDataset，用于传输的数据集对象。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>RuntimeError</strong> - 如果提供了分布式训练的文件路径但读取失败。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.to_json">
<code class="sig-name descname">to_json</code><span class="sig-paren">(</span><em class="sig-param">filename=''</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.to_json" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据处理管道序列化为JSON字符串，如果提供了文件名，则转储到文件中。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>filename</strong> (str) - 保存JSON文件的路径（包含文件名）。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>str，数据处理管道序列化后的JSON字符串。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.use_sampler">
<code class="sig-name descname">use_sampler</code><span class="sig-paren">(</span><em class="sig-param">new_sampler</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.use_sampler" title="Permalink to this definition">¶</a></dt>
<dd><p>为当前数据集对象更换一个新的采样器。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>new_sampler</strong> (Sampler) ：替换的新采样器。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># dataset is an instance object of Dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># use a DistributedSampler instead</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">new_sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">DistributedSampler</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span><span class="o">.</span><span class="n">use_sampler</span><span class="p">(</span><span class="n">new_sampler</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.CelebADataset.zip">
<code class="sig-name descname">zip</code><span class="sig-paren">(</span><em class="sig-param">datasets</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.CelebADataset.zip" title="Permalink to this definition">¶</a></dt>
<dd><p>将数据集对象和输入的数据集对象或者数据集对象元组按列进行合并压缩。输入数据集对象中不能有重名的列。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>datasets</strong> (Union[tuple, class Dataset]) - 数据集对象的元组或单个数据集对象与当前数据集对象一起合并压缩。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>ZipDataset，合并压缩后的数据集对象。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Create a dataset which is the combination of dataset and dataset_1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">zip</span><span class="p">(</span><span class="n">dataset_1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.dataset.Cifar10Dataset.html" class="btn btn-neutral float-right" title="mindspore.dataset.Cifar10Dataset" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.dataset.Caltech256Dataset.html" class="btn btn-neutral float-left" title="mindspore.dataset.Caltech256Dataset" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>